package com.cloudcc.mobile.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.inputmethod.InputMethodManager;

import com.cloudcc.cloudframe.bus.EventEngine;
import com.cloudcc.cloudframe.bus.IEventLife;
import com.cloudcc.cloudframe.bus.MenuToggleEventR;
import com.cloudcc.mobile.event.isshow;
import com.cloudcc.mobile.view.base.BaseFragmentActivity;
import com.cloudcc.mobile.view.fragment.BeauInfoFragment;
import com.litesuits.android.log.Log;

import de.greenrobot.event.EventBus;

public class BeauInfoActivity extends BaseFragmentActivity implements IEventLife {
	private BeauInfoFragment fragment;
	public static BeauInfoActivity inatance = null;

	@Override
	public void init(Bundle savedInstanceState) {
		super.init(savedInstanceState);
		register();
		inatance = this	;
		fragment = new BeauInfoFragment();
		fragment.setArguments(getIntent().getExtras());
		getSupportFragmentManager().beginTransaction()
				.add(getContainerId(), fragment).commit();
		String bName=getIntent().getStringExtra("beau.name");
		Log.d("---name",bName);
	}
	public void close(){
		
		InputMethodManager imm = (InputMethodManager)getSystemService(mContext.INPUT_METHOD_SERVICE);  
		boolean is = imm .isActive();
		imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(),0);   
//		imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);  
		
	}
	@Override
	protected void onNewIntent(Intent intent) {
		finish();
		startActivity(intent);
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		// Log.d("huidiao", "sss"+data.getStringExtra("name")+requestCode);

		if (resultCode == RESULT_OK) {
			String a = data.getStringExtra("name");
			String[] c = a.split(",");
			for (int i = 0; i < c.length; i++) {
				if (!c[i].equals("")) {
					String name = " @[" + c[i] + "]";
					getUserID listener =  fragment.dialog;
					listener.getUser(name);
				}
			}
		}
	}

	@Override
	public void register() {
		EventEngine.register(this);
	}

	@Override
	public void unRegister() {
		EventEngine.uregister(this);
	}
	public void onEventMainThread(MenuToggleEventR event) {
		if (menu_R == null) {
			return;
		}
		if (event.isToggle) {
			if (event.open) {
			} else {
				menu_R.toggle();
				initRequestDataTz();
			}
		} else {

		}
	}

	public interface getUserID {
		void getUser(String userName);
	}
//	float x1 = 0;
//	float x2 = 0;
//	float y1 = 0;
//	float y2 = 0;
//	isshow issh = new isshow();
//	isleft isle = new isleft();
//	@Override
//	public boolean dispatchTouchEvent(MotionEvent event) {
//		if (event.getAction() == MotionEvent.ACTION_DOWN) {
//			// 当手指按下的时候
////			Log.d("zuobiao", "(" + x1 + "," + y1 + ")(" + x2 + "," + y2 + ")");
//			x1 = event.getX();
//			y1 = event.getY();
//		}
//		if (event.getAction() == MotionEvent.ACTION_UP) {
//			// 当手指离开的时候
//			x2 = event.getX();
//			y2 = event.getY();
//			Log.d("zuobiao", "(" + x1 + "," + y1 + ")(" + x2 + "," + y2 + ")");
//			if ((x1 - x2 > 400)) {
//				Log.d("zuobiao", "shang");
//				issh.isshow = true;
////				Toast.makeText(BeauInfoActivity.this, "zuobian", 1).show();
//				EventBus.getDefault().post(issh);
//			} else if ((x2 - x1 > 400)) {
//				Log.d("zuobiao", "xia");
//				issh.isshow = false;
////				Toast.makeText(BeauInfoActivity.this, "youbian", 1).show();
//				EventBus.getDefault().post(issh);
//			}
//
//		}
//		return super.dispatchTouchEvent(event);
//	}
	isshow issh = new isshow();
	@Override
	public boolean dispatchTouchEvent(MotionEvent event) {
		 if(event.getAction() == MotionEvent.ACTION_DOWN){  
			float x =  event.getX();
			float y = event.getY();
//			getMaxHeight();
//			Log.d("panduanweizhi", x+":::::::"+y+"::::"+height+"::");
//			if(y<((height/10)*9)){
				issh.isxiaoshi = true;
				issh.Y = (int) y;
				Log.d("panduanweizhi", x+":::::::"+y+"::::"+issh.Y);
				EventBus.getDefault().post(issh);
//			}
		 }
		
		// TODO Auto-generated method stub
		return super.dispatchTouchEvent(event);
	}
	int height ;
	public void getMaxHeight(){
		DisplayMetrics metric = new DisplayMetrics();  
		getWindowManager().getDefaultDisplay().getMetrics(metric);  
		height= metric.heightPixels;   // 屏幕高度（像素） 
	}

	@Override
	protected void onStop() {
		super.onStop();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		unRegister();
	}
}
